package demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-21
 * Time: 11:51
 */
public class Demo4 {
    public static void main(String[] args) {
        // ExecutorService threadPool = Executors.newFixedThreadPool(4);//newFixedThreadPool这个方法最大线程数和核心线程数一样

        ExecutorService threadPool = Executors.newCachedThreadPool();//newCachedThreadPool这个方法线程可以无限增加，在线程池里有很多线程

        for (int i = 0; i < 1000; i++) {
            int id = i;
            threadPool.submit(() -> {
                System.out.println("hello " + id + ", " + Thread.currentThread().getName());
            });
        }
    }
}
